
const { GameModel } = require('../model/gameModel');
const { CellModel } = require('../model/cellModel');
const g = require('../utils/global');

cc.Class({
    extends: cc.Component,

    properties: {
        // 显示区域
        grid: {
            type: cc.Node,
            default: null,
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.gameModel = new GameModel();
        this.gameModel.init(4);
        // 绑定数据
        const gridView = this.grid.getComponent('gridView');
        gridView.setController(this);
        // this.gameModel.printCells();
        gridView.initWithCellModels(this.gameModel.cells);
    },

    start () {
    },

    getScore() {
        return this.gameModel.score;
    },

    selectCell: function (cellPos) {
        return this.gameModel.selectCell(cellPos);

    },

    cleanCmd: function () {
        for(let i = 1; i <= g.GRID_ROWS; ++i) {
            for(let j = 1; j <= g.GRID_COLUMNS; ++j) {
                if(this.gameModel.cells[i][j]) {
                    this.gameModel.cells[i][j].cleanCmd();
                }
            }
        }
    }
});
